package com.ygqh.baby.controller.admin;

import java.util.Date;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgPublish;
import com.ygqh.baby.service.YgPublishService;

@Controller
@RequestMapping("/admin/publish")
public class PublishController  extends BaseController<Object, java.lang.Long>{
	@Autowired
	private YgPublishService ygPublishService;
	
	@RequestMapping("searchPublish")
	@ResponseBody
	public Map<String,Object> searchPublish(String q,QueryInfo queryInfo,Date startDate,Date endDate,String pStatus,Long id,String userName) {	
		
		ResultSet<YgPublish> resultSet=ygPublishService.search(queryInfo,q,"create_time","desc",pStatus,startDate,endDate,id,userName);
		
		return resultSet.toDatatables(null);
	}
	
	//审批
	@RequestMapping("approvePublish")
	@ResponseBody
	public Message approvePublish(Long id,String remark,String status){
		YgPublish ygPublish=new YgPublish();
		ygPublish.setId(id);
		ygPublish.setCheckRemark(remark);
		ygPublish.setCheckStatus(status);
		ygPublish.setCheckBy(getSession().getTrueName());
		ygPublish.setCheckTime(new Date());		
		ygPublishService.update(ygPublish);		
		
		return SUCCESS_MESSAGE;
	}
	/**
	 * 批量审批
	 * @param id
	 * @param remark
	 * @param status
	 * @return
	 */
		@RequestMapping("batchApprovePublish")
		@ResponseBody
		public Message batchApprovePublish(Long[] ids,String remark,String status){
				
			ygPublishService.updateBatchChechStatus(getSession().getTrueName(),status, ids);
			
			return SUCCESS_MESSAGE;
		}
	//排序
	@RequestMapping("sortPublish")
	@ResponseBody
	public Message sortPublish(Long id,Long sortNum){
			YgPublish ygPublish=new YgPublish();
			ygPublish.setId(id);
		    ygPublish.setSortNum(sortNum);			
			ygPublishService.update(ygPublish);		
			
			return SUCCESS_MESSAGE;
		}
	
}
